import React from 'react'
import Sun from './Sun'
import { useDispatch, useSelector } from 'react-redux/es/exports'
import { setName } from './store/createAction'

export default function Child() {
  const username = useSelector((state) => state.username)

  //得到dispatch方法 修改数据
  const dispatch = useDispatch()
  return (
    <div>
      <h5>Child-{username}</h5>
      <button
        onClick={() => {
          dispatch(setName('教的什么东西'))
        }}
      >
        改名字
      </button>
      <Sun></Sun>
    </div>
  )
}
